# _*_ coding : utf-8 _*_
# @Time : 2022/9/12 14:55
# @Author : 软柠柠吖
# @File : 02-字符串统计案例
# @Project : pythonProject

import xlrd
from xlutils.copy import copy

wb = xlrd.open_workbook(r'D:\桌面\test\test.xlsx')
ws = wb.sheet_by_name('分数表')

nwb = copy(wb)
nws = nwb.get_sheet('分数表')

for row_num in range(1, ws.nrows):
    txt = ws.cell_value(row_num, 1)
    nws.write(row_num, 2,
              '优：{}良：{}中：{}差：{}'.format(
                  txt.count('优'),
                  txt.count('良'),
                  txt.count('中'),
                  txt.count('差')
              )
              )
    # print(ws.row_values(row_num))
nws.write(0, 2, '等级统计')
nwb.save(r'D:\桌面\test\test.xlsx')